<?php

/**
 * 创作者的模型
 * 2022-03/03 --by low
 */
class Issuer_model extends CI_Model
{

    public function issuerList($select = '*', $page, $pageSize, $keyword = '')
    {
        if ($keyword) {
            $this->db->like('title', $keyword);
        }
        return $this->db->select($select)->where(['status' => 9])
            ->limit($pageSize, ($page - 1) * $pageSize)->get('1_issuer')->result_array();
    }

    public function issuerInfo($id)
    {
        return $this->db->select(['id', 'title', 'thumb', 'description'])
            ->where(['id' => $id, 'status' => 9])->get('1_issuer')->row_array();
    }

    public function issuerTransfer($item)
    {
        if ($item['thumb']) {
            $item['thumb'] = dr_thumb($item['thumb'], 550, 550);
        }
        return $item;
    }

    // 更新创作者获利
    public function operateField($id, $value)
    {
        if (empty($value)) {
            return false;
        }
        return $this->db->where('id', $id)->set('total_money', 'total_money +' . $value, false)->update('1_issuer');
    }

    // 取出创作者的作品
    public function creatorWorks($creator)
    {
        return $this->db->select('id,thumb,creator')
            ->{is_array($creator) ? 'where_in' : 'where'}('creator', $creator)->limit(50)
            ->get('1_issuer_works')->result_array();
    }
}